package com.jmb.apiplatform.controller;


import com.jmb.apiplatform.common.PageResult;
import com.jmb.apiplatform.common.Result;
import com.jmb.apiplatform.exception.ValidException;
import com.jmb.apiplatform.pojo.DbDao;
import com.jmb.apiplatform.pojo.DbVO;
import com.jmb.apiplatform.service.DbService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Tag(name = "数据源中心")
@RequestMapping("/db")
@RestController
public class DbController {
    @Autowired
    private DbService dbService;

    @PostMapping("/save")
    public Result saveDb(@RequestBody DbDao dbDao) throws ValidException {
        dbService.saveDb(dbDao);
        return Result.success();
    }
    @GetMapping("/{id}")
    private Result getDbId(@PathVariable Integer id) throws ValidException {
        DbDao dbDao = dbService.getDbId(id);
        return Result.success(dbDao);
    }
    @GetMapping
    private Result ListDao(DbVO DbVO) throws ValidException {
        PageResult<DbDao> daoPageResult = dbService.ListDao(DbVO);
        return Result.success(daoPageResult);
    }
    @PostMapping("/modify")
    public Result modifyDb(@RequestBody DbDao dbDao) throws ValidException {
        dbService.modifyDb(dbDao);
        return Result.success();
    }
    @GetMapping("/remove/{id}")
    public Result deleteDb(@PathVariable Integer id) throws ValidException {
        dbService.deleteDb(id);
        return Result.success();
    }
    @GetMapping("/check/{id}")
    public Result dbConnectInfo(@PathVariable Integer id) throws ValidException {
        String dbConnectInfo = dbService.dbConnectInfo(id);
        return Result.success(dbConnectInfo);
    }
}
